package com.wiley.service;

import java.net.MalformedURLException;

import org.openqa.selenium.By;

import com.wiley.publicMethod.BasePage;
import com.wiley.publicMethod.LoggerControler;

import io.appium.java_client.android.AndroidDriver;

public class MessagePage extends BasePage {
	
	LoggerControler log;

	/**
	 * 页面元素
	 */
	//我的
	public static final By mine_item_loc = By.id(BaseId + "mine_item");
	
	//点击登录按钮
	public static final By login_tv_loc = By.id(BaseId + "login_tv");

	//登录界面：用户
	public static final By login_user_loc = By.id(BaseId + "login_user");

	//登录界面：密码
	public static final By login_password_loc = By.id(BaseId + "login_password");

	//登录界面：登录好豆
	public static final By login_haodou_loc = By.id(BaseId + "login_haodou");
	
	//用户昵称
	public static final By nick_tv_loc = By.id(BaseId + "nick_tv");
	
	//消息
	public static final By message_loc = By.name("消息");
	
	//消息列表 tv_title
	public static final By tv_title_loc = By.id(BaseId + "tv_title");
	
	//转到上一层级
	public static final By back_loc = By.name("转到上一层级");
	
	/**
	 * 操作方法
	 */
	//点击我的
	public void clickMineItem(){
		this.clickEle(mine_item_loc);
	}
	
	// 登录
	public void login(){
		this.clickEle(login_tv_loc);
		this.sendKeys(login_user_loc, "18250862110");
		this.sendKeys(login_password_loc, "fgwvip123");
		this.clickEle(login_haodou_loc);
	}
	
	/**
	 * 消息
	 */
	public void viewMessage(){
		if(this.isElementPresent(nick_tv_loc)){
			this.clickEle(message_loc);
			int titleNum = this.getElesLength(tv_title_loc);
			if(titleNum == 3){
				log.info("列表获取成功！");
			}
			this.clickEle(back_loc);
		}else{
			this.login();
			this.clickEle(message_loc);
			int titleNum = this.getElesLength(tv_title_loc);
			if(titleNum == 3){
				log.info("列表获取成功！");
			}
			this.clickEle(back_loc);
		}
	}
	
	/**
	 * 业务封装
	 * @throws MalformedURLException 
	 * @throws InterruptedException 
	 */
	public void message(Class name) throws MalformedURLException {
		log = this.MyLogger(name);
		AndroidDriver driver = super.SetDriver();
		this.clickMineItem();
		this.viewMessage();
		log.info("该case测试通过！");
	}
}
